<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Necesario emplearlo con el BaseController, ya que especifica la ruta al template actual
 */
if ( ! function_exists('static_url'))
{
	function static_url($uri = '')
	{
		//base_url() . "static/admin/"
		$CI =& get_instance();
		$template_name = $CI->config->item("template_name");
		
		return base_url() . "static/" . $template_name . "/" . $uri;	
	}
}


function add_param_url($params){
	$url_params = $_GET;
	foreach($params as $param_name => $param_value){
		$url_params[$param_name] = $param_value;
	}
	
	$CI =& get_instance();
	$url = "";
	$segments = $CI->uri->segment_array();
	$total_segments = count($segments);
	//Prevenimos la paginacion
	for($i=1; $i<=$total_segments; $i++){
		if($segments[$i] == "page"){
			$i++;
		} else{
			$url .= "/{$segments[$i]}";
		}
	}
	
	foreach($url_params as $url_param_name => $url_param_value){
		if(strpos($url, "?") !== FALSE){
			$url .= "&";
		} else{
			$url .= "?";
		}
		$url .= "$url_param_name=$url_param_value";
	}
	
	return $url;
	
}